/* eslint-disable indent */
'use strict'

/**
 * 门店表
 */

module.exports = app => {
    const { TEXT, STRING, INTEGER, DATE } = app.Sequelize

    const Place = app.model.define('place', {
        id: {
            type: INTEGER,
            primaryKey: true,
            autoIncrement: true
        },
        barcode: {
            type: STRING,
            allowNull: false,
            comment: '网吧编码'
        },
        barname: {
            type: STRING,
            allowNull: false,
            comment: '网吧名称'
        },
        expires: {
            type: DATE,
            allowNull: false,
            comment: '到期时间'
        },
        status: {
            type: INTEGER,
            allowNull: true,
            comment: '状态',
            defaultValue: 1
        },
        logged_at: {
            type: DATE,
            comment: '最后登录时间'
        },
        version: {
            type: STRING,
            allowNull: false,
            comment: 'SDK版本'
        }
    })

    // 建立关联关系
    Place.associate = async () => {
        Place.hasMany(app.model.Desktopcfg, {
            foreignKey: 'pid',
            as: 'desktops',
            targetKey: 'id'
        })
    }

    return Place
}
